//
//  VHBounceView.m
//  FruitHelper
//
//  Created by 赵隆杰 on 2021/12/11.
//

#import "VHBounceView.h"
#import <FFPopup.h>

@interface VHBounceView()


@end

@implementation VHBounceView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self initview];
    }
    return self;
}

- (void)initview {
    
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView cornerSideType:kViewSideTypeTop withCornerRadius:12];
    [self addSubview:bgView];
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 70)];
    [bgView addSubview:topView];
    UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bounds.size.width - 10 - 50, 10, 50, 50)];
    closeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [closeBtn setTitleColor:kColor666666 forState:UIControlStateNormal];
    [closeBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(dismissBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:closeBtn];
    
    self.contentView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topView.frame), self.frame.size.width, self.frame.size.height - CGRectGetMaxY(topView.frame))];
    [bgView addSubview:self.contentView];
    
}


- (void)dismissBtnClick
{
    if (self.closeBlock) {
        self.closeBlock();
    }
}

- (void)dismissView
{
    [self dismissBtnClick];
}
-(void)show
{
    FFPopup *popup = [FFPopup popupWithContentView:self showType:FFPopupShowType_BounceInFromBottom dismissType:FFPopupDismissType_BounceOutToBottom maskType:FFPopupMaskType_Dimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
    popup.showInDuration = .25;
    FFPopupLayout layout = FFPopupLayoutMake(FFPopupHorizontalLayout_Center, FFPopupVerticalLayout_Bottom);
    [popup showWithLayout:layout];
    self.closeBlock = ^{
        [popup dismissAnimated:YES];
    };
}

@end
